package com.example.erp.controller;

import com.example.erp.dto.loginDTO.LoginDTO;
import com.example.erp.service.LoginService;
import com.example.erp.utils.Result;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/admin")
public class LoginController {
    @Autowired
    private LoginService loginService;

    @Autowired
    private DefaultKaptcha defaultKaptcha;

    // 生成验证码接口
    @GetMapping("/auth/captcha")
    public Result generateCaptcha(HttpServletRequest request) {
        return loginService.generateCaptcha(request);
    }

    // 登录接口
    @PostMapping("/auth/login")
    public Result login(@RequestBody LoginDTO loginDTO,HttpServletRequest request) {
        return loginService.login(loginDTO, request);
    }
    /**
     * 菜单路由
     * */
    @GetMapping("/getRouters")
    public Result getRouters(@RequestHeader("token") String token) {
        return loginService.getRouters(token);
    }
    /**
     * 用户信息
     * */
    @GetMapping("/getInfo")
    public Result getInfo(@RequestHeader("token") String token) {
        return loginService.getInfo(token);
    }
}
